<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">仪表盘</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="datas">
      <div></div>
      <div class="dataitem">
        <h3>昨日散户<span class="sp1">sanhu</span></h3>
        <p>{{sanhu}}</p>
      </div>
      <div class="dataitem">
        <h3>昨日油卡<span class="sp2">cards</span></h3>
        <p>{{youka}}</p>
      </div>
      <div class="dataitem">
        <h3>昨日会员<span class="sp3">users</span></h3>
        <p>{{huiyuan}}</p>
      </div>
      <div class="dataitem"
           style="margin-right:0">
        <h3>余额不足<span class="sp4">users</span></h3>
        <p>{{lens}}</p>
      </div>
    </div>
    <el-card>
      <!-- 2. 为ECharts准备一个具备大小（宽高）的Dom -->

      <div class="sel">
        <el-select v-model="value"
                   placeholder="请选择"
                   @change="selects(value)">
          <el-option v-for="item in options"
                     :key="item.value"
                     :label="item.label"
                     :value="item.value">
          </el-option>
        </el-select>
      </div>
      <div class="bing">
        <div class="left">

          <h4>各家油卡消费情况饼图</h4>
          <div id="card"></div>
        </div>
        <div id="text"
             class="item">
          <h4>各会员消费情况饼图</h4>
          <div id='main'></div>
        </div>
      </div>
      <div class="bing">
        <div class="items"
             id='ca'
             ref='conWidth'>
          <h4>收入情况折线图</h4>
          <div id="custom"></div>
        </div>
        <div class="items">
          <h4>销售情况折线图</h4>
          <div id="main3"></div>
        </div>
      </div>
      <!-- <div class="items"
           id='ca'
           ref='conWidth'>
        <h4>收入情况折线图</h4>
        <div id="custom"></div>
      </div>
      <div class="items">
        <h4>销售情况折线图</h4>
        <div id="main3"></div>
      </div> -->

    </el-card>
    <el-card>
      <h3>以下为余额不足10000元的客户，请提醒客户及时充值</h3>
      <el-table :data="data"
                border
                stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="name"
                         label="客户名称">
        </el-table-column>
        <el-table-column prop="totals"
                         label="客户余额"></el-table-column>
      </el-table>
    </el-card>

  </div>
</template>
<script>
var echarts = require('echarts')
export default {
  data () {
    return {
      tz: 0,
      value: 7,
      options: [{
        value: 7,
        label: '近7天各数据情况显示'
      }, {
        value: 14,
        label: '近2周各数据情况显示'
      }, {
        value: 30,
        label: '近1个月各数据情况显示'
      }],
      data: [],
      sanhu: 0,
      youka: 0,
      huiyuan: 0,
      lens: 0
    }
  },
  created () {
    this.change()
    this.getTz()
  },
  mounted () {
    this.getWidth()
    this.getData()
    this.getCustom()

  },
  methods: {
    selects (item) {
      this.value = item
      this.getData()
    },
    getData () {
      //销售情况折线图
      var myChart3 = echarts.init(document.getElementById('main3'))
      this.$http.get('/api/reportUrealData', {
        params:
          { tz: this.tz, das: this.value }
      }).then(res => {
        myChart3.setOption(res.data);
      })
      ////客户情况报表 
      var myChart = echarts.init(document.getElementById('main'))
      this.$http.get('/api/reportShouruData', {
        params:
          { tz: this.tz, das: this.value }
      }).then(res => {
        myChart.setOption(res.data);
      })

      //两种色号的油进出货情况

      //油卡情况报表
      var card = echarts.init(document.getElementById('card'))
      this.$http.get('/api/reportCardData', {
        params:
          { tz: this.tz, das: this.value }
      }).then(res => {
        card.setOption(res.data)
      })
      //收入情况（散户，客户，油卡）管理报表
      var custom = echarts.init(document.getElementById('custom'))
      this.$http.get('/api/reportCustomData', {
        params:
          { tz: this.tz, das: this.value }
      }).then(res => {
        let option = res.data
        // console.log(res.data.series[0].data[0])
        this.sanhu = res.data.series[0].data[0]
        this.youka = res.data.series[1].data[0]
        this.huiyuan = res.data.series[2].data[0]
        custom.setOption(option);
        // window.onresize = custom.resize;
        window.onresize = function () {
          custom.resize();
          myChart3.resize();
          card.resize();
          myChart.resize();
        }
      })
      custom.resize();
      myChart3.resize();
      card.resize();
      myChart.resize();
    },
    //获取剩余资金在10000万以下的会员
    getCustom () {
      this.$http.get('/api/customlt').then(res => {
        if (res.status === 200) {
          this.data = res.data
          this.lens = res.data.length
        }
      })
      // window.onresize = custom.resize;
    },
    //查询当前是手机端 ，还是PC端
    _isMobile () {
      let flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
      return flag;
    },

    change () {

      if (this._isMobile()) {
        this.$router.push('panel')
        // this.$router.replace('/m_index');
      } else {
        // alert("pc端");
        // this.$router.replace('/pc_index');
      }

    },
    //获取当前时区
    getTz () {
      const das = new Date()
      this.tz = (-(das.getTimezoneOffset() / 60))
    },
    getWidth () {
      let aa = this.$refs.conWidth.clientWidth + 'px';
      console.log(aa)
    },
  },
  watch: {
    // this.chart.resize()
  }
}
</script>
<style scoped>
.items {
  width: 98%;
  height: 400px;
  color: #fff !important;
  margin-bottom: 20px;
  padding-top: 10px;
}
.el-card .items h4 {
  text-align: center;
  font-size: 18px;
  line-height: 30px;
  height: 30px;
  color: #333;
}
.el-card .items div {
  width: 100%;
  height: 360px;
  margin: 0 auto;
}
.el-card .items div canvas {
  width: 1300px !important;
}
.bing {
  display: flex;
  width: 95%;
  margin: 0 auto;
  justify-items: center;
  justify-content: center;
}

.bing div {
  width: 50%;
  height: 500px;
  color: #fff !important;
  padding: 20px 0 0 0;
  box-sizing: border-box;
}

.bing div div {
  width: 100%;
  height: 450px;
  margin: 0 auto;
  padding-left: 15px;
}
.bing div h4 {
  text-align: center;
  font-size: 16px;
  line-height: 20px;
  height: 30px;
  color: #000;
}
h3 {
  padding: 50px 0 80px 0;
}
.datas {
  margin: 20px;
  overflow: hidden;
  display: flex;
}
.datas .dataitem {
  width: 25%;
  background: #fff;
  margin-right: 10px;
  box-sizing: content-box;
  flex: 1;
}
.datas .dataitem h3 {
  border-bottom: 1px solid #ccc;
  padding: 20px;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
}
.datas .dataitem h3 span {
  float: right;
  padding: 3px 8px;
  border-radius: 4px;
  color: #fff;
}
.sp1 {
  background: #1c84c6;
}

.sp2 {
  background: #23c6c8;
}
.sp3 {
  background: #1ab394;
}
.sp4 {
  background: #ed5565;
}
.datas .dataitem p {
  font-size: 30px;
  padding-left: 20px;
  text-align: left;
  color: #428bca;
  height: 80px;
  line-height: 80px;
}
</style>